In general, when a high-level language such as C or C++ is compiled to executable machine code, a translation occurs from a human readable source code language (e.g., C or C++) into a processor executable machine language, which includes a set of machine instructions that are executable by a processor.
Most compilation processes, or “flows,” involve the linking of compiled code by software known as a linker. This linking is necessary because many computer programs are developed in such a way that they are comprised of multiple source files or libraries, but compilation is typically accomplished one file at a time. Linking is the process of joining all the compiled files into a single executable. In general, code optimization is the process of making code faster to execute and less demanding on limited resources like memory and processing power. Various compilation techniques optimize code at some point during the compilation process, or prepare it for optimization at run-time. Typically, the “scope,” or extent of an optimization is a single file or library (a library being a collection of related files). One of the points in the process that optimization can take place is at link time, which occurs before run time.
Link time optimization (LTO) is a powerful compilation technique that allows the broadening of the optimization scope in programming languages that otherwise compile a program one file at a time. One of the responsibilities of a linker is to resolve symbols across a compiled file. In LTO, the linker can resolve symbols not only across one file, but across multiple files that are to be linked in the final executable, which thereby allows the optimization scope to include multiple files.
A linker script is another utility used in conjunction with a linker, often in embedded application environments. It is used to express a fine degree of control over the final executable image—and namely, the particular sections thereof—produced during the compilation (and optimization) process. Often, though, if a user tries to use a linker script in an LTO environment, the linker utilized in LTO and the linker script itself come into conflict. During an LTO build process, the linker is responsible for informing a compiler about external dependencies between various files and libraries and any other users of LTO resident objects, in order to resolve symbols across the entire scope. The process of informing a compiler of external dependencies can become especially complex and difficult when a linker script is involved in the LTO process. If the linker does not inform the compiler of these dependencies, no proper code generation is possible. Current implementations of this process are conservative in nature, and not highly optimized.